package pers.leeyns.rd.name;

import pers.leeyns.rd.chinese.RandomChineseGenerator;

/**
 * @description 中文姓名随机生成
 * @author Leeyns
 * @date 2016年2月3日
 */
public class RandomChineseNamedGenerator extends RandomChineseGenerator{
	private static final long serialVersionUID = -6909109382666835758L;
	public static RandomChineseNamedGenerator build(){
		return new RandomChineseNamedGenerator();
	}
	/**
	 * 百家姓-单姓
	 */
	private static final String NAMED_SINGLE_CHARACTER = "赵钱孙李周吴郑王冯陈诸卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卡齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏家封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘景詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴翟阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后荆红游竺权逯盖后桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于单于太叔申屠公孙仲孙轩辕令狐钟离宇文长孙慕容鲜于闾丘司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚闫法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福百家姓终";
	/**
	 * 复姓
	 */
	private static final String NAMED_DOUBLE_CHARACTER = "鲍俎百里碧鲁伯赏北堂单于陈林淳于第五东方东郭东门段干独孤端木范姜哥舒公良公孙公西公冶公羊缑亢谷梁归海赫连胡母呼延黄方皇甫即墨夹谷晋楚况后梁丘令狐陆费闾丘闾邱明哲墨哈慕容万俟钠兰南宫南郭南门年爱欧阳濮阳漆雕亓官谯萱屈突壤驷汝鄢司马司空司寇司徒上官商牟申屠侍其疏束叔孙太史太叔澹台涂钦拓拔完完完颜王子闻人微生巫马乌雅铁笔西门夏侯许世轩辕闫法羊舌阳佟耶律有琴尉迟余佴宇文岳帅乐正宰父子车子阳宗政左丘张简章佳长孙郑余仲孙钟离诸葛颛孙";
	/**
	 * 女-名字-模板
	 */
	private static final String NAMED_SECOND_MM="秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽 ";  
    /**
     * 男-名字-模板
     */
    private static final String NAMED_SECOND_GG="伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘"; 

    private static final String NAMED_SECOND_GGMM = NAMED_SECOND_MM+NAMED_SECOND_GG;
	/**
	 * 随机获取一个名字
	 * @param length 名字的长度
	 * @param isFuXing 是否复姓
	 * @return
	 */
	public  String getName(int length,boolean isFuXing){
		return isFuXing ? getDoubleFirstName() + getRandomChinese(length - 2):getSingleFirstName() + getRandomChinese(length -1);
	}
	
	/**
	 * 获取单姓
	 * @return
	 */
	public String getSingleFirstName(){
		return String.valueOf(NAMED_SINGLE_CHARACTER.charAt(this.nextInt(NAMED_SINGLE_CHARACTER.length())));
	}
	/**
	 * 获取复姓
	 * @return
	 */
	public String getDoubleFirstName(){
		int x = this.nextInt(NAMED_DOUBLE_CHARACTER.length());
		x = x % 2 > 0 ? x-1:x;
		return String.valueOf(NAMED_DOUBLE_CHARACTER.charAt(x))+NAMED_DOUBLE_CHARACTER.charAt(x+1);
	}
	
	/**
	 * 通过预设模板随机获取中文 名
	 * @param sex
	 * @param length
	 * @return
	 */
	public String getNormalSecondName(int sex,int length){
		if(sex == 1){//男
			return this.getRandomChinese(NAMED_SECOND_GG, length);
		}else if(sex == 2){//女
			return this.getRandomChinese(NAMED_SECOND_MM, length);
		}else{
			return this.getRandomChinese(NAMED_SECOND_GGMM, length);
		}
	}
	
	/**
	 * 获取常用姓名
	 * @param length 名字长度
	 * @param isFuXing 是否为复姓
	 * @param sex 性别  1=男 2=女 ，3 = 不分男女
	 * @return
	 */
	public String getNormalNamed(int length,boolean isFuXing,int sex){
		return isFuXing ? (getDoubleFirstName() + getNormalSecondName(sex, length - 2)): (getSingleFirstName() + getNormalSecondName(sex,length -1)); 
	}
	
	public static void main(String[] args) {
		RandomChineseNamedGenerator r =	RandomChineseNamedGenerator.build();
		while(true){
			//生成单姓3字名字
			System.out.println(r.getNormalNamed(3, false, 3));
			//生成 复姓四字名字
//			System.out.println(r.getNormalNamed(4, true, 3));
		}
	}
}
